package top.psjj.news.service.impl;

import top.psjj.news.dao.NewsDao;
import top.psjj.news.dao.TypeDao;
import top.psjj.news.po.TNews;
import top.psjj.news.po.TType;
import top.psjj.news.service.TypeService;

import java.util.List;

/**
 * @Auther:小陈的Java
 */
public class TypeServiceImpl implements TypeService {
    private TypeDao typeDao = new TypeDao();
    private NewsDao newsDao = new NewsDao();
    @Override
    public List<TType> queryAll() throws Exception {
        return typeDao.queryAll();
    }

    @Override
    public void add(TType type) throws Exception {
        typeDao.add(type);
    }

    @Override
    public TType queryTypeById(int id) throws Exception {
        return typeDao.queryTypeById(id);
    }

    @Override
    public void modify(TType type) throws Exception {
        typeDao.update(type);
    }

    @Override
    public void del(int id) throws Exception {
        typeDao.del(id);
    }

    @Override
    public List<TType> queryAllRelationNews() throws Exception {
        List<TType> result = typeDao.queryAll();
        for (TType type :result){
            Integer typeId = type.getId();
            List<TNews> newsList = newsDao.queryNewsBytypeId(typeId);
            type.setNews(newsList);
        }
        return result;
    }
}
